<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');


$course_id = mysql_real_escape_string(strip_tags($_GET['cid']));

$query = "SELECT *, c.id AS cid, csub.id AS sid
 		  FROM courses c
		  JOIN course_subjects csub ON csub.id = c.course_subject_id
		  WHERE c.id = '$course_id'";
$result = mysql_query($query);
$row=mysql_fetch_assoc($result);
$subject_id = $row['sid'];
$subject_name = $row['subject_title'];
$abbreviation = $row['abbreviation'];
$course_number = $row['course_number'];
$course_name = $row['title'];


echo "<p>";
	echo "<a href='index.php?sid=$subject_id&id=$course_id'>&lt;&lt; Back to Sections Portal</a><br />";
echo "</p>";
echo "<h1>Add Section for $abbreviation $course_number</h1>";

//counting variable
$i = 0;

$query="SELECT * FROM instructors";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

echo '<p>';

echo "<form action='add_do.php' method='post'>";

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Section Number: </b></td>";
		echo "<td><input type='text' name='section_num'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Instructor: </b></td>";
		echo "<td>";
			echo "<select name='instructor'>";
				while ($i < $num_rows)
				{
					$instructor_id=mysql_result($result,$i,"id");
					$first_name=mysql_result($result,$i,"first_name");
					$last_name=mysql_result($result,$i,"last_name");
					echo "<option value=$instructor_id>$last_name, $first_name</option>";
					$i++;
				}
			echo "</select>";	
		echo "</td>";	
	echo "</tr>";
	
	$i=0;
	
	$get_room_type=mysql_query("SELECT * FROM classroom_types");
	$num_types=mysql_numrows($get_room_type);
	
	echo "<tr>";
		echo "<td><b>Room Type: </b></td>";
		echo "<td>";
			echo "<select name='room_type'>";
				while ($i < $num_types)
				{
					$type_description=mysql_result($get_room_type,$i,"description");
					$type_id=mysql_result($get_room_type,$i,"id");
					echo "<option value=$type_id>$type_description</option>";
					$i++;
				}
			echo "</select>";	
		echo "</td>";	
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Max Students: </b></td>";
		echo "<td><input type='text' name='max_s'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Honors: </b></td>";
		echo '<td>';
			echo "<select name='honors'>";
				echo "<option value=1>Yes</option>";
				echo "<option value=0>No</option>";
			echo "</select>";
		echo '</td>';
	echo "</tr>";
	
	$get_semesters = mysql_query("
		SELECT *
		FROM seasons
		JOIN semesters
		ON semesters.season_id=seasons.id
		ORDER BY seasons.season, semesters.year");
	
	$num_semesters = mysql_numrows($get_semesters);
	
	$i=0;
	
	echo "<tr>";
		echo "<td><b>Semester: </b></td>";
		echo "<td>";
			echo "<select name='semester'>";
				while ($i < $num_semesters)
				{
					$semester_id=mysql_result($get_semesters,$i,"semesters.id");
					$year=mysql_result($get_semesters,$i,"semesters.year");
					$season=mysql_result($get_semesters,$i,"seasons.season");
					echo "<option value=$semester_id>$season $year</option>";
					$i++;
				}
			echo "</select>";	
		echo "</td>";	
	echo "</tr>";
	
//end table tag
echo "</table>";


echo "<input type='hidden' name='cid' value='$course_id'>";
echo "<input type='hidden' name='sid' value='$subject_id'>";
echo "<p><input type='submit'></p>";
echo '</form>';



?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>